package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.ws.rs.DefaultValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.BaseCo;
import com.engineering.elink.co.SkillCo;
import com.engineering.elink.common.ErrorType;
import com.engineering.elink.service.SkillService;
import com.engineering.elink.util.ResJsonUtil;

@RestController
@CrossOrigin
@RequestMapping("/api/skill")
@Api(value="工程技能接口")
public class SkillController {
	
	@Autowired
	private SkillService skillService;
	
	/**
	 * 获取热搜词
	 */
	@RequestMapping(value="/getKeyWord",method = RequestMethod.GET)
	@ApiOperation(value = "获取热搜词")
	public Map<String, Object>getKeyWord(
			@ApiParam(value="显示条数,默认为6条",required=false,defaultValue="6")
			@RequestParam(value = "count",required=false,defaultValue="6")int count){
		
		return skillService.getKeyWord(count);
	}
	
	/**
	 * 获取工程技能列表
	 */
	@RequestMapping(value="/getList",method = RequestMethod.GET)
	@ApiOperation(value = "技能列表")
	public Map<String, Object> getList(@ModelAttribute @Valid SkillCo co,
			@ApiParam(value="资料显示条数,默认为6条",defaultValue="6") @RequestParam("count") @DefaultValue("6") int count){
		return ResJsonUtil.getMap(ErrorType.SUCCESS, skillService.getSkillsList(co,count));
	}
	
	/**
	 * 下载排行
	 */
	@RequestMapping(value="/getDownLoadRank",method = RequestMethod.GET)
	@ApiOperation(value = "下载排行")
	public Map<String, Object> getDownLoadRank(
			@ApiParam(value="显示条数,默认为10条",defaultValue="10") @RequestParam("count") @DefaultValue("10") int count){
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS, skillService.getDownLoadRank(count));
	}
	
	/**
	 * 技能详情
	 */
	@RequestMapping(value="/get",method = RequestMethod.GET)
	@ApiOperation(value = "技能详情")
	public Map<String, Object> get(
			@ApiParam(value="技能id",required=true) @RequestParam(value = "skillId",required=true)Integer skillId,HttpServletRequest request){
		
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId=null;
		if(userInfo!=null && userInfo.get("userId")!=null)
			userId =  userInfo.get("userId").toString();
		
		return skillService.get(skillId,userId);
	}
	
	/**
	 * 单个技能资料
	 */
	@RequestMapping(value="/getSigleSkillFile",method = RequestMethod.GET)
	@ApiOperation(value = "单个技能资料")
	public Map<String, Object> getSigleSkillFile(
			@ApiParam(value="显示条数,默认为10条",defaultValue="10") @RequestParam("count") @DefaultValue("10") int count,
			@ApiParam(value="技能ID",required=true) @RequestParam("skillId") int skillId){
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS, skillService.getSigleSkillFile(skillId, count));
	}
	
	/**
	 * 单个技能视频
	 */
	@RequestMapping(value="/getSigleSkillVideo",method = RequestMethod.GET)
	@ApiOperation(value = "单个技能视频")
	public Map<String, Object> getSigleSkillVideo(
			@ApiParam(value="显示条数,默认为10条",defaultValue="10") @RequestParam("count") @DefaultValue("10") int count,
			@ApiParam(value="技能ID",required=true) @RequestParam("skillId") int skillId){
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS, skillService.getSigleSkillVideo(skillId, count));
	}
	
	/**
	 * 
	 * 相关资料
	 */
	@RequestMapping(value="/getSameFile",method = RequestMethod.GET)
	@ApiOperation(value = "相关资料")
	public Map<String, Object> getSameFile(
			@ApiParam(value="显示条数,默认为10条",defaultValue="10") @RequestParam("count") @DefaultValue("10") int count,
			@ApiParam(value="技能ID",required=true) @RequestParam("skillId") int skillId){
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS, skillService.getSameSkillFile(skillId, count));
	}
	
	
	@RequestMapping(value="/getSameSkill",method=RequestMethod.GET)
	@ApiOperation(value="相关技能")
	public Map<String,Object> getSameSkill(@ModelAttribute @Valid BaseCo co,
			@ApiParam(value="当前技能id",required=false) @RequestParam(value = "skillId",required=false)Integer skillId){
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS,skillService.getSameSkill(co,skillId));
	}
	
	/**
	 * 获取首页工程技能体系
	 */
	@RequestMapping(value="/getEnginSkillFile",method = RequestMethod.GET)
	@ApiOperation(value = "获取首页工程技能体系")
	public Map<String, Object> getEnginSkillFile(@ApiParam(value="一级分类ID",required=true) @RequestParam("tcId") int tcId,
			@ApiParam(value="显示条数,默认为5条",required=false,defaultValue="5")
			@RequestParam(value = "count",required=false,defaultValue="5")int count){
		
		return skillService.getEnginSkillFile(tcId,count);
	}
	
}
